package x_yeyue.obj;

import x_yeyue.GameWin;
import x_yeyue.utils.GameUtils;

import java.awt.*;

public class LittleBoss1 extends GameObj{
    int health = 10;

    public LittleBoss1(Image img, int width, int height, int x, int y, double speed, GameWin frame) {
        super(img, width, height, x, y, speed, frame);
    }

    public LittleBoss1(int x, int y) {
        super(x, y);
    }

    public LittleBoss1() {
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        if(y < 150){
            y += 2;
        }else{
            x += speed;
            if(x > 400 || x < 10){
                speed = -speed;
            }
        }

        for (ShellObj shellObj : GameUtils.shellObjList) {
            if(this.getRec().intersects(shellObj.getRec()) && health > 0){
                // 碰撞之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x + 100, y + 100);
                GameUtils.explodeObjsList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                shellObj.setX(-100);
                shellObj.setY(-100);
                GameUtils.removeList.add(shellObj);
                health --;
            }else if(this.getRec().intersects(shellObj.getRec()) && health <= 0){
                // 碰撞之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x + 50, y + 50);
                GameUtils.explodeObjsList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                // 敌方小boss被击毁的时候产生补给
                BossGiftObj bossGiftObj = new BossGiftObj(this.x, this.y);
                GameUtils.bossgiftObjList.add(bossGiftObj);
                GameUtils.gameObjList.addAll(GameUtils.bossgiftObjList);

                shellObj.setX(-100);
                shellObj.setY(-100);
                GameUtils.removeList.add(shellObj);
                this.x = -200;
                this.y = -200;
                GameWin.score += 5;
                GameUtils.removeList.add(this);
            }
        }

    }
}
